<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../") ; }
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../../include/garennes_apb.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 $requete = var_courante ("requete", 0, null) ;
 $millesime = millesime (0) ;
 $apb_actif = garennes_apb_actif ($millesime) ;
 
 $nom_photo1 = "../../images/photo_" ;
 $nom_photo2 = "non_" ;
 $nom_photo3 = "ok.png" ;
 
 If (IsSet ($requete))
  {
   Switch ($requete)
    {
     // Insertion d'une sous-discipline
     Case 0 : $nom = var_courante ("nom", 0, "") ;
              $type = var_courante ("type", 0, 0) ;
	      $langue = var_courante ("langue", 0, 0) ;
              $ok = SQL_commande ("INSERT INTO sous_disciplines (nom,type) VALUES ('".filtrage ($nom)."','".($type+($langue<<1))."')", $id_sql) ;
	      $requete = 0 ;
              Break ;
     // Effacement d'une sous-discipline
     Case 1 : $id_sous_discipline = var_courante ("id_sous_discipline", 0, "") ;
              $ok = SQL_commande ("DELETE FROM sous_disciplines WHERE id_sous_discipline='".$id_sous_discipline."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE services_prof SET sous_discipline='0' WHERE sous_discipline='".$id_sous_discipline."'", $id_sql) ;
	      $requete = 0 ;
	      Break ;
     // Debut de modification
     Case 2 : $id_sous_discipline = var_courante ("id_sous_discipline", 0, "") ;
              $resultat = SQL_commande ("SELECT * FROM sous_disciplines WHERE id_sous_discipline='".$id_sous_discipline."'", $id_sql) ;
              $modif = SQL_tableau_associatif ($resultat, "") ;
	      $requete = 3 ;
              Break ;
     // Fin de modification
     Case 3 : $id_sous_discipline = var_courante ("id_sous_discipline", 0, "") ; $nom = var_courante ("nom", 0, "") ; $type = var_courante ("type", 0, 0) ; $langue = var_courante ("langue", 0, 0) ;
              $ok = SQL_commande ("UPDATE sous_disciplines SET nom='".filtrage ($nom)."',type='".($type+$langue*2)."' WHERE id_sous_discipline='".$id_sous_discipline."'", $id_sql) ;
	      $requete = 0 ;
              Break ;
     // Modif etat
     Case 4 : $id_sous_discipline = var_courante ("id", 0, "") ; $type = var_courante ("type", 0, Null) ; $langue = var_courante ("langue", 0, Null) ;
              If ($id_sous_discipline > 0)
	       {
	        $tp = SQL_commande ("SELECT type FROM sous_disciplines WHERE id_sous_discipline='".$id_sous_discipline."' LIMIT 1", $id_sql) ;
		$t = SQL_ligne_suivante ($tp) ;
	        If ($type == Null) { $type = ($t [0]&1) ; }
	        If ($langue == Null) { $langue = ($t [0]>>1) ; }
                $ok = SQL_commande ("UPDATE sous_disciplines SET type='".($type+($langue<<1))."' WHERE id_sous_discipline='".$id_sous_discipline."'", $id_sql) ;
	       }
	      $requete = 0 ;
              Break ;
    }
  }
 Else
  { $requete = 0 ; $modif ["nom"] = "" ; $modif ["id_sous_discipline"] = $modif ["type"] = 0 ; }
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0' LIMIT 1", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 
 Echo "<HTML><HEAD>" ;
 entete_html ("Garennes", "travail", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Include ("./gestion_sous_disciplines.js") ;
 Echo "</HEAD>" ;
 
 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\" onContextMenu=\"return false\">" ;
 Echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" STYLE=\"border-collapse:collapse\">" ;
 Echo "<TR>" ;
 Echo "<TD></TD>" ;
 Echo "<TD WIDTH=\"100%\" ALIGN=\"CENTER\"><FONT COLOR=\"#0000FF\"><B>Gestion&nbsp;des&nbsp;sous-disciplines.</B></FONT></TD>" ;
 Echo "<TD><A HREF=\"javascript:ouvrefenetre('./aide.php?aide=1&rep=".$_SESSION ["repertoire_config"]."',350,650);\" OLDREF><IMG SRC=\"../images/aide.png\" BORDER=\"0\"></A></TD>" ;
 Echo "</TR>" ;
 Echo "<TABLE>" ;
 Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"0\" STYLE=\"border-collapse:collapse\">" ;
 Echo "<TR>" ;
 Echo "<TD vALIGN=\"TOP\">" ;
 Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"0\" BGCOLOR=\"".$l ["lien"]."\" STYLE=\"border:1px solid #000000;border-collapse:collapse\">" ;
 Echo "<TR>" ;
 Echo "<TD COLSPAN=\"4\">" ;
 Echo "<FORM METHOD=\"POST\" ACTION=\"./gestion_sous_disciplines.php\" NAME=\"ajout\" onSubmit=\"return verifie()\">" ;
 Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"0\" WIDTH=\"100%\" STYLE=\"border-collapse:collapse\">" ;
 Echo "<TR><TD ALIGN=\"CENTER\" COLSPAN=\"".(2+(6*$apb_actif))."\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>" ;
 If ($requete == 0) { Echo "Ajouter" ; } Else { Echo "Modifier" ; }
 Echo "</B>&nbsp;</FONT></TD></TR>" ;
 Echo "<TR BGCOLOR=\"".$l ["nom"]."\">" ;
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Nom&nbsp;</TD>" ;
 If ($apb_actif == 1)
  {
   Echo "<TD ALIGN=\"CENTER\" style=\"border-left:1px solid #000000;\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Sp&eacute;cialit&eacute;e&nbsp;</TD>" ;
   Echo "<TD ALIGN=\"CENTER\" style=\"border-left:1px solid #000000;\" colspan=\"5\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Niveau&nbsp;Langue&nbsp;Vivante&nbsp;</TD>" ;
  }
 Echo "<TD BGCOLOR=\"".$l ["lien"]."\"></TD>" ;
 Echo "</TR>" ;
 Echo "<TR>" ;
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<INPUT TYPE=\"TEXT\" NAME=\"nom\" VALUE=\"".$modif ["nom"]."\" SIZE=\"11\" MAXLENGTH=\"10\">&nbsp;</FONT></TD>" ;
 If ($apb_actif == 1)
  {
   Echo "<TD ALIGN=\"CENTER\" style=\"border-left:1px solid #000000;\">&nbsp;<INPUT TYPE=\"checkbox\" NAME=\"type\" VALUE=\"1\"" ; If (($modif ["type"]&1) == 1) { Echo " checked" ; }
   Echo ">&nbsp;</TD>" ;
   Echo "<td align=\"center\" id=\"l0\" style=\"border-left:1px solid #000000;\"><input type=\"radio\" name=\"langue\" value=\"0\" id=\"f0\" onchange=\"javascript:activation_langue();\"" ;
   If (($modif ["type"]>>1) == 0) { Echo " checked" ; }
   Echo ">&nbsp;Aucun&nbsp;</td>" ;
   For ($i = 1 ; $i <= 4 ; $i++)
    {
     Echo "<td align=\"center\" id=\"l".$i."\"><input type=\"radio\" name=\"langue\" value=\"".$i."\" id=\"f".$i."\" onchange=\"javascript:activation_langue();\"" ;
     If (($modif ["type"]>>1) == $i) { Echo " checked" ; }
     Echo ">&nbsp;LV".$i."&nbsp;&nbsp;</td>" ;
    }
   Echo "<script type=\"text/javascript\">activation_langue();</script>" ;
  }
 Echo "<TD ALIGN=\"CENTER\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_sous_discipline\" VALUE=\"".$modif ["id_sous_discipline"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"".$requete."\">" ;
 Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/ajouter.png\" ALT=\"Ajouter/Modifier une sous-discipline\" VALUE=\"Ajouter\" BORDER=\"0\">" ;
 Echo "</TD>" ;
 Echo "</TR>" ;
 Echo "<TR><TD COLSPAN=\"8\">&nbsp;</TD></TR>" ;
 Echo "</TABLE>" ;
 Echo "</FORM>" ;
 Echo "</TD></TR></TABLE>" ;
 Echo "</TD></TR>" ;
 
 If ($requete == 0)
  {
   // Verification si tout est utilise
   /*
   $presence_disc = SQL_commande ("SELECT d.id_sous_discipline, COUNT(s.id_service_prof)
                                     FROM sous_disciplines d, services_prof s
                                    WHERE d.id_sous_discipline=s.sous_discipline
			         GROUP BY d.id_sous_discipline
			         ORDER BY d.nom", $id_sql) ;
   */
   // Sous-disciplines deja saisies
   $resultat = SQL_commande ("SELECT * FROM sous_disciplines ORDER BY nom", $id_sql) ;
   If (SQL_nbr_lignes ($resultat))
    {
     $nbr_sd = 0 ;
     Echo "<TR><TD HEIGHT=\"5\"></TD></TR>" ;
     Echo "<TR>" ;
     Echo "<TD vALIGN=\"TOP\">" ;
     Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"0\" BGCOLOR=\"".$l ["couleur_fond"]."\" STYLE=\"border:1px solid #000000;border-collapse:collapse\">" ;
     Echo "<TR BGCOLOR=\"".$l ["lien"]."\">" ;
     If ($apb_actif == 1)
      {
       Echo "<TD ALIGN=\"CENTER\" rowspan=\"2\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Action</B>&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"LEFT\" rowspan=\"2\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Nom</B>&nbsp;</FONT></TD>" ;
       Echo "<td align=\"center\" colspan=\"2\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Admission&nbsp;Post&nbsp;Bac</B>&nbsp;</FONT></TD>" ;
       Echo "</tr><tr BGCOLOR=\"".$l ["lien"]."\">" ;
       Echo "<TD ALIGN=\"center\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Sp&eacute;cialit&eacute;e</B>&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"center\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<b>Niveau&nbsp;Langue&nbsp;Vivante</b>&nbsp;</TD>" ;
      }
     Else
      {
       Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Action</B>&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Nom</B>&nbsp;</FONT></TD>" ;
      }
     Echo "</TR>" ;
     //$presence = SQL_ligne_suivante ($presence_disc) ;
     While ($ligne = SQL_tableau_associatif ($resultat, ""))
      {
       /*
       $ok_presence = 0 ;
       If ($presence [0] == $ligne ["id_sous_discipline"])
        {
	 If ($presence [1] > 0) { $ok_presence = 1 ; }
	 $presence = SQL_ligne_suivante ($presence_disc) ;
	}
       */
       $verif_sous_disc = SQL_commande ("SELECT id_service_prof FROM services_prof WHERE sous_discipline='".$ligne ["id_sous_discipline"]."' LIMIT 1", $id_sql) ;
       $nbr_sd++ ;
       Echo "<TR" ;
       If ($nbr_sd%2 == 0) { Echo " BGCOLOR=\"".$l ["nom"]."\"" ; }
       Echo ">" ;
       Echo "<TD ALIGN=\"CENTER\">" ;
       Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" WIDTH=\"100%\" STYLE=\"border-collapse:collapse\">" ;
       Echo "<TR>" ;
       Echo "<FORM ACTION=\"./gestion_sous_disciplines.php\" METHOD=\"POST\">" ;
       Echo "<TD" ;
       If (SQL_nbr_lignes ($verif_sous_disc) == 0) { Echo " COLSPAN=\"2\"" ; }
       Echo ">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_sous_discipline\" VALUE=\"".$ligne ["id_sous_discipline"]."\">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"2\">" ;
       Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/edition.png\" TITLE=\"&Eacute;diter la sous-discipline\" BORDER=\"0\">" ;
       Echo "</TD>" ;
       Echo "</FORM>" ;
       If (SQL_nbr_lignes ($verif_sous_disc) == 0)
        {
         Echo "<FORM ACTION=\"./gestion_sous_disciplines.php\" METHOD=\"POST\" onSubmit=\"return valide('".Str_Replace ("'", " ", $ligne ["nom"])."')\">" ;
         Echo "<TD>" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_sous_discipline\" VALUE=\"".$ligne ["id_sous_discipline"]."\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"1\">" ;
         Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/effacer.png\" TITLE=\"Supprimer la sous-discipline\" BORDER=\"0\">" ;
         Echo "</TD>" ;
         Echo "</FORM>" ;
        }
       Echo "</TR>" ;
       Echo "</TABLE>" ;
       Echo "</TD>" ;
       Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["nom"]."&nbsp;</FONT></TD>" ;
       
       If ($apb_actif == 1)
        {
         Echo "<TD ALIGN=\"center\">&nbsp;<a href=\"./gestion_sous_disciplines.php?id=".$ligne ["id_sous_discipline"]."&type=".(($ligne ["type"]&1)+1%2)."&requete=4\"><img src=\"".$nom_photo1 ;
         If (($ligne ["type"]&1) == 0) { Echo $nom_photo2 ; }
         Echo $nom_photo3."\" border=\"0\"></a>&nbsp;</TD>" ;
         
         Echo "<td align=\"center\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" style=\"border-collapse:collapse\"><tr>" ;
         Echo "<td>&nbsp;<a href=\"./gestion_sous_disciplines.php?id=".$ligne ["id_sous_discipline"]."&langue=0&requete=4\"><img src=\"".$nom_photo1 ; If (($ligne ["type"]>>1) != 0) { Echo $nom_photo2 ; }
         Echo $nom_photo3."\" border=\"0\"></a>Aucun&nbsp;&nbsp;</td>" ;
         For ($i = 1 ; $i <= 4 ; $i++)
          {
	   Echo "<td>&nbsp;<a href=\"./gestion_sous_disciplines.php?id=".$ligne ["id_sous_discipline"]."&langue=".$i."&requete=4\"><img src=\"".$nom_photo1 ;
           If (($ligne ["type"]>>1) != $i) { Echo $nom_photo2 ; }
           Echo $nom_photo3."\" border=\"0\"></a>LV".$i."&nbsp;&nbsp;" ;
          }
         Echo "</td></tr></table></td>" ;
	}
       Echo "</tr>" ;
      }
     Echo "</TD>" ;
     Echo "</TR>" ;
     Echo "</TABLE>" ;
    }
   Else
    {
    }
  }
 Echo "</TABLE>" ;
 Echo "</FORM>" ;
 Echo "</BODY></HTML>" ;
?>